﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MockBusiness;
using MockDataTransferObject;

namespace Presentation.Reporting
{
    public partial class TimeSheetReport : System.Web.UI.Page
    {
        private ContractBusiness _contractBusiness;
        protected void Page_Init(object sender, EventArgs e)
        {
            _contractBusiness = ContractBusiness.RetrieveInstance();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] != null && Session["user"] is User)
            {
                User user = (User)Session["User"];
                if (user.Role.RoleName != "Admin" & user.Role.RoleName != "Consultant")
                {
                    Response.Redirect("../NotAuthorized.aspx");
                }
                
                if (!Page.IsPostBack)
                {
                    DateTime nowDate = DateTime.Now;
                    DateTime startDate = new DateTime(nowDate.Year, nowDate.Month, 1);
                    StartdateTextBox.Text = String.Format("{0:MM/dd/yyyy}", startDate);
                    EnddateTextBox.Text = String.Format("{0:MM/dd/yyyy}", nowDate);
                    //Loading default
                    odsStatusName.SelectParameters["FromDate"].DefaultValue = StartdateTextBox.Text;
                    odsStatusName.SelectParameters["ToDate"].DefaultValue = EnddateTextBox.Text;
                    odsStatusName.DataBind();
                    TimeSheetReportViewer.LocalReport.Refresh();
                }
            }
            else
            {
                Response.Redirect("../LogOn.aspx");
            }
        }

        protected void AddButton_Click(object sender, EventArgs e)
        {
            odsStatusName.SelectParameters["FromDate"].DefaultValue = StartdateTextBox.Text;
            odsStatusName.SelectParameters["ToDate"].DefaultValue = EnddateTextBox.Text;
            odsStatusName.DataBind();
            TimeSheetReportViewer.LocalReport.Refresh();
        }
    }
}